﻿using B.Auth.APi.Application.Command.Users;
using B.Auth.Domain.Entity;
using B.Auth.Domain.Repository;
using B.Auth.Enum;
using MediatR;
using Microsoft.AspNetCore.Mvc.ApiExplorer;

namespace B.Auth.APi.Application.CommandHand
{
    public class GetUserNameCommandHand : IRequestHandler<GetUserNameCommand, ApiResult<List<User>>>
    {

        private readonly IBaseRepository<User> db;

        public GetUserNameCommandHand(IBaseRepository<User> db)
        {
            this.db = db;
        }

        public Task<ApiResult<List<User>>> Handle(GetUserNameCommand request, CancellationToken cancellationToken)
        {
            var result = new ApiResult<List<User>>();

            var users = new List<User>();
            
            foreach (var item in request.userids)
            {

                var list = db.GetAll().Where(x => x.Id == item).ToList();
                users.AddRange(list);
               
            }
            result.data = users;      
            return Task.FromResult(result);
        }
    }
}
